package com.bt.lms.ui.page.teaching.arrange;

import com.bt.lms.ui.action.teaching.arrange.*;
import com.bt.lms.ui.vo.CourseInfo;
import com.bt.lms.ui.page.sys.style.BtnStyle;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Cursor;
import javafx.scene.Node;
import javafx.scene.control.*;
import javafx.scene.control.cell.PropertyValueFactory;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;
import javafx.scene.paint.Color;
import javafx.scene.text.Font;

import java.util.ArrayList;
import java.util.List;

/**
 * 按照课程查看界面
 */
public class PageArrangeNoExecuteList extends VBox {

    /**
     * 按照课程查看界面长
     */
    private double preWidth = 1280;
    /**
     * 批量导入报名信息界面高
     */
    private double preHeight = 800;

    /**
     * 列名默认长度
     */
    private double columnPreWidth = 200;

    public PageArrangeNoExecuteList() {

        this.setPrefSize(preWidth, preHeight);
        this.setPadding(new Insets(5));
        this.setSpacing(20);

        //顶部横向盒子
        HBox topHBox = new HBox();
        initTopHBox(topHBox);
        //三个按钮横向盒子
        HBox threeBtnHBox = new HBox();
        initThreeBtnHBox(threeBtnHBox);
        ///条件搜索区域横向盒子
        HBox searchHBox = new HBox();
        initSearchHBox(searchHBox);
        //新增教学安排按钮横向盒子
        HBox addTeachingArrangeHBox = new HBox();
        initAddTeachingArrangeHBox(addTeachingArrangeHBox);

        //表格盒子
        VBox tableVBox = new VBox();
        initTableVBox(tableVBox);
        //页码横向盒子
        HBox pageNumHBox = new HBox();
        initPageNumHBox(pageNumHBox);

        ObservableList<Node> children = this.getChildren();
        children.addAll(topHBox, threeBtnHBox, searchHBox, addTeachingArrangeHBox, tableVBox, pageNumHBox);


    }


    /**
     * 页码横向盒子
     *
     * @param pageNumHBox
     */
    private void initPageNumHBox(HBox pageNumHBox) {
        pageNumHBox.setSpacing(20);
        pageNumHBox.setPadding(new Insets(10));
        pageNumHBox.setAlignment(Pos.CENTER_RIGHT);
        //首页标签
        Label homeLab = new Label("<<首页");
        homeLab.setTextFill(Color.rgb(108, 221, 83));
        homeLab.setFont(new Font(20));
        //上一页标签
        Label previousPageLab = new Label("<<上一页");
        previousPageLab.setTextFill(Color.rgb(108, 221, 83));
        previousPageLab.setFont(new Font(20));
        //第一页按钮
        Button onePageBtn = new Button("1");
        onePageBtn.setPrefWidth(27);
        onePageBtn.setPrefHeight(30);
        //第二页按钮
        Button twoPageBtn = new Button("2");
        twoPageBtn.setPrefWidth(27);
        twoPageBtn.setPrefHeight(30);
        //第三页按钮
        Button threePageBtn = new Button("3");
        threePageBtn.setPrefWidth(27);
        threePageBtn.setPrefHeight(30);
        //第四页按钮
        Button fourPageBtn = new Button("4");
        fourPageBtn.setPrefWidth(27);
        fourPageBtn.setPrefHeight(30);
        //下一页标签
        Label nextPageLab = new Label("下一页>>");
        nextPageLab.setFont(new Font(20));
        nextPageLab.setTextFill(Color.rgb(108, 221, 83));
        //尾页标签
        Label endPageLab = new Label("尾页>>");
        endPageLab.setFont(new Font(20));
        endPageLab.setTextFill(Color.rgb(108, 221, 83));
        //总记录数条
        Label totalPageLab = new Label("总页数100条");
        totalPageLab.setFont(new Font(20));
        totalPageLab.setTextFill(Color.rgb(255, 65, 55));
        //条数文本框
        TextField countTF = new TextField();
        countTF.setPrefWidth(100);
        // /10标签
        Label tenLab = new Label("/10");
        tenLab.setFont(new Font(20));
        //GO按钮
        Button goBtn = new Button("GO");


        ObservableList<Node> children = pageNumHBox.getChildren();
        children.addAll(homeLab, previousPageLab, onePageBtn, twoPageBtn, threePageBtn, fourPageBtn, nextPageLab, endPageLab, totalPageLab, countTF, tenLab, goBtn);
    }

    /**
     * 表格盒子
     *
     * @param tableVBox
     */
    private void initTableVBox(VBox tableVBox) {



        //表格
        TableView tableView = new TableView<>();

        TableColumn serialNumColumn = new TableColumn<>("序号");
        serialNumColumn.setPrefWidth(columnPreWidth);
        TableColumn courseNameColumn = new TableColumn<>("课程名称");
        courseNameColumn.setPrefWidth(columnPreWidth);

        TableColumn courseTeacherColumn = new TableColumn<>("授课教师");
        courseTeacherColumn.setPrefWidth(columnPreWidth);
        TableColumn startCourseTimeColumn = new TableColumn<>("开课时间");
        startCourseTimeColumn.setPrefWidth(columnPreWidth);
        TableColumn finishCourseTimeColumn = new TableColumn<>("结课时间");
        finishCourseTimeColumn.setPrefWidth(columnPreWidth);


        TableColumn statusColumn = new TableColumn<>("状态");
        statusColumn.setPrefWidth(columnPreWidth);
        TableColumn operationColumn = new TableColumn<>("操作");
        operationColumn.setPrefWidth(columnPreWidth);
        //操作列盒子1
        HBox hBox1 = new HBox();
        hBox1.setSpacing(5);
        //编辑按钮
        Button course1editBtn = new Button("编辑");
        //编辑按钮事件
        PageCourseLookEditBtnAction pageCourseLookEditBtnAction = new PageCourseLookEditBtnAction();
        course1editBtn.setOnAction(pageCourseLookEditBtnAction);
        course1editBtn.setCursor(Cursor.HAND);
        //删除按钮
        Button course1deleteBtn1 = new Button("删除");


        //提示框
        course1deleteBtn1.setOnAction(new EventHandler<ActionEvent>() {
            @Override
            public void handle(ActionEvent event) {
                Alert alert = new Alert(Alert.AlertType.WARNING);
                alert.setContentText("您确定删除吗？");
                alert.show();
            }
        });
        course1deleteBtn1.setOnMouseEntered(new EventHandler<MouseEvent>() {
            @Override
            public void handle(MouseEvent event) {
                course1deleteBtn1.setCursor(Cursor.HAND);
            }
        });
        //开课确认按钮
        Button course1startBtn1 = new Button("开课确认");

        //提示框
        course1startBtn1.setOnAction(new EventHandler<ActionEvent>() {
            @Override
            public void handle(ActionEvent event) {
                Alert alert = new Alert(Alert.AlertType.CONFIRMATION);
                alert.setContentText("您确定开课吗？");
                alert.show();
            }
        });
        course1startBtn1.setOnMouseEntered(new EventHandler<MouseEvent>() {
            @Override
            public void handle(MouseEvent event) {
                course1startBtn1.setCursor(Cursor.HAND);
            }
        });
        hBox1.getChildren().addAll(course1editBtn, course1deleteBtn1, course1startBtn1);

        //课程2操作列盒子
        HBox hBox2 = new HBox();
        //取消按钮
        Button course2cancelBtn = new Button("取消");
        hBox2.getChildren().add(course2cancelBtn);
        course2cancelBtn.setOnMouseEntered(new EventHandler<MouseEvent>() {
            @Override
            public void handle(MouseEvent event) {
                course2cancelBtn.setCursor(Cursor.HAND);
            }
        });


        //课程名称盒子
        HBox courseNameHBox = new HBox();
        //课程名标签
        Label educationLab = new Label("教育心理学");
        educationLab.setTextFill(Color.rgb(61, 140, 205));
        courseNameHBox.getChildren().add(educationLab);
        PageCourseLookCourseLabAction pageCourseLookCourseLabAction = new PageCourseLookCourseLabAction();
        educationLab.setOnMouseClicked(pageCourseLookCourseLabAction);
        educationLab.setCursor(Cursor.HAND);

        //数学盒子
        HBox matchHBox = new HBox();
        //数学标签
        Label matchLab = new Label("数学");
        matchLab.setTextFill(Color.rgb(61, 140, 205));
        matchHBox.getChildren().add(matchLab);

        //英语盒子
        HBox EnglishHBox = new HBox();
        //英语标签
        Label EnglishLab = new Label("英语");
        EnglishLab.setTextFill(Color.rgb(61, 140, 205));
        EnglishHBox.getChildren().add(EnglishLab);
        //物理盒子
        HBox physicsHBox = new HBox();
        //物理标签
        Label physicsLab = new Label("物理");
        physicsLab.setTextFill(Color.rgb(61, 140, 205));
        physicsHBox.getChildren().add(physicsLab);

        //化学盒子
        HBox chemistryHBox = new HBox();
        //化学标签
        Label chemistryLab = new Label("化学");
        chemistryLab.setTextFill(Color.rgb(61, 140, 205));
        chemistryHBox.getChildren().add(chemistryLab);


        //模拟表中数据
        CourseInfo courseInfo1 = new CourseInfo("1", courseNameHBox, "必修", "学位专业课", "张老师", "2012-09-01", "2012-10-01", "2012-11-01", "2012-11-02", "50/50", "未发布", hBox1);
        CourseInfo courseInfo2 = new CourseInfo("2", matchHBox, "必修", "基础课", "王老师", "2012-9-10", "2012-10-10", "2012-11-10", "2012-11-12", "30/30", "已确认开课", hBox2);

        //数据集合
        List<CourseInfo> courseInfoList = new ArrayList<>();
        courseInfoList.add(courseInfo1);
        courseInfoList.add(courseInfo2);


        //将数据集合转换成Javafx组件集合
        ObservableList<CourseInfo> courseInfos = FXCollections.observableArrayList(courseInfoList);
        tableView.setItems(courseInfos);

        //映射到表中
        serialNumColumn.setCellValueFactory(new PropertyValueFactory<CourseInfo, String>("serialNum"));
        courseNameColumn.setCellValueFactory(new PropertyValueFactory<CourseInfo, String>("courseName"));

        courseTeacherColumn.setCellValueFactory(new PropertyValueFactory<CourseInfo, String>("courseTeacher"));
        startCourseTimeColumn.setCellValueFactory(new PropertyValueFactory<CourseInfo, String>("startCourseTime"));
        finishCourseTimeColumn.setCellValueFactory(new PropertyValueFactory<CourseInfo, String>("finishCourseTime"));

        statusColumn.setCellValueFactory(new PropertyValueFactory<CourseInfo, String>("status"));
        operationColumn.setCellValueFactory(new PropertyValueFactory<CourseInfo, String>("operation"));


        tableView.getColumns().addAll(serialNumColumn, courseNameColumn, courseTeacherColumn, startCourseTimeColumn, finishCourseTimeColumn, statusColumn, operationColumn);
        tableVBox.getChildren().add(tableView);


    }

    /**
     * 初始化新增教学安排按钮横向盒子
     *
     * @param addTeachingArrangeHBox
     */
    private void initAddTeachingArrangeHBox(HBox addTeachingArrangeHBox) {

        addTeachingArrangeHBox.setPadding(new Insets(10));
        //新增教学安排按钮
        Button addTeachingArrangeBtn = new Button("新增教学安排");
        PageMainAddTeachingArrangeBtnAction pageMainAddTeachingArrangeBtnAction = new PageMainAddTeachingArrangeBtnAction();
        addTeachingArrangeBtn.setOnAction(pageMainAddTeachingArrangeBtnAction);

        addTeachingArrangeBtn.setOnMouseEntered(new EventHandler<MouseEvent>() {
            @Override
            public void handle(MouseEvent event) {
                addTeachingArrangeBtn.setCursor(Cursor.HAND);
            }
        });
        BtnStyle.addBtn(addTeachingArrangeBtn);

        addTeachingArrangeHBox.getChildren().addAll(addTeachingArrangeBtn);

    }


    /**
     * 条件搜索区域横向盒子
     *
     * @param searchHBox
     */
    private void initSearchHBox(HBox searchHBox) {
        //搜索区域横向盒子间距
        searchHBox.setSpacing(15);
        searchHBox.setPadding(new Insets(10));
        //所属学习单位标签
        Label learningCenLab = new Label("所属学习单位");
        //所属学习单位下拉框
        ComboBox learningCenCB = new ComboBox<>();
        learningCenCB.getItems().add("全部");
        learningCenCB.getItems().add("北京师范大学");
        learningCenCB.getSelectionModel().selectFirst();

        //适用层次标签
        Label levelLab = new Label("适用层次");
        //适用层次下拉框
        ComboBox levelCB = new ComboBox<>();
        levelCB.getItems().add("全部");
        levelCB.getItems().add("免费师范生");
        levelCB.getItems().add("免费师范生教育硕士");
        levelCB.getItems().add("职后教育");
        levelCB.getItems().add("其他");
        levelCB.getSelectionModel().selectFirst();


        //课程编号/课程名称标签
        Label courseNum = new Label("课程编号/名称");
        ////课程编号/课程名称文本框
        TextField courseNumTF = new TextField();
        courseNumTF.setPromptText("输入课程名称");
        //搜索按钮
        Button searchBtn = new Button("搜索");
        BtnStyle.cancelBtn(searchBtn);
        BtnStyle.cancelBtnAction(searchBtn);


        searchHBox.getChildren().addAll(learningCenLab, learningCenCB, levelLab, levelCB, courseNum, courseNumTF, searchBtn);

    }

    /**
     * 三个按钮横向盒子
     *
     * @param threeBtnHBox
     */
    private void initThreeBtnHBox(HBox threeBtnHBox) {
        threeBtnHBox.setSpacing(20);
        //未实施的教学安排按钮
        Button noStartBtn = new Button("未实施的教学安排");
        BtnStyle.cancelBtn(noStartBtn);
        BtnStyle.cancelBtn(noStartBtn);
        noStartBtn.setOnMouseEntered(new EventHandler<MouseEvent>() {
            @Override
            public void handle(MouseEvent event) {
                noStartBtn.setCursor(Cursor.HAND);
            }
        });
        //实施中的教学安排按钮
        Button processBtn = new Button("实施中的教学安排");
        BtnStyle.cancelBtn(processBtn);
        BtnStyle.cancelBtnAction(processBtn);
        //实施中的教学安排按钮事件
        PageCourseLookProcessBtnAction pageCourseLookProcessBtnAction = new PageCourseLookProcessBtnAction();
        processBtn.setOnAction(pageCourseLookProcessBtnAction);
        processBtn.setCursor(Cursor.HAND);
        //已完成的教学安排按钮
        Button finishBtn = new Button("已完成的教学安排");
        BtnStyle.cancelBtn(finishBtn);
        BtnStyle.cancelBtnAction(finishBtn);
        //已完成的教学安排按钮事件
        PageCourseLookFinishBtnAction pageCourseLookFinishBtnAction = new PageCourseLookFinishBtnAction();
        finishBtn.setOnAction(pageCourseLookFinishBtnAction);
        finishBtn.setCursor(Cursor.HAND);
        ObservableList<Node> children = threeBtnHBox.getChildren();
        children.addAll(noStartBtn, processBtn, finishBtn);

    }

    /**
     * 顶部横向盒子
     *
     * @param topHBox
     */
    private void initTopHBox(HBox topHBox) {
        topHBox.setSpacing(20);
        topHBox.setPadding(new Insets(2));
        //顶部标签
        Label topLab = new Label("当前位置：🏠>教学管理>教学安排>未实施的教学安排");
        topLab.setFont(new Font(20));//设置字体大小
        ObservableList<Node> children = topHBox.getChildren();
        children.addAll(topLab);
    }


}
